/**
 * Created by novem on 15/9/25.
 */
window.onload=function(){
    var url = getUrl();
    $.jsonp({
        url: 'http://'+url+'/api/photobook/option_spotsphoto',
        data: {},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            var complied_tpl = juicer($("#fabu_tpl").text());
            var html = complied_tpl.render(data);
            $("#selected").append(html);
        },
        error: function (xOptions, textStatus) {
        }
    });
    $(".ui-btn-lg").on("click",function(){
        var urlList = getPics();
        var name=$("#photo_title").val();
        var userId = getUserId();
        var spotsId =$("#selected").find("option:checked").attr("id");
        if(!name){
            showToast("画册名不能为空~");
            return;
        }
        if(!spotsId){
            showToast("请选择景点画册~");
            return;
        }
        if(!urlList){
            showToast("请至少上传一张图片~");
            return;
        }
        $.jsonp({
            url: 'http://'+url+'/api/photobook/dosave',
            data: {name:name,userId:userId,spotsId:spotsId,urlList:urlList},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {
                if(data.succ==true){
                    //取得用户ID
                    showToast("发布成功~");
                    location.href="wode_huace_chuangjian.html";
                }

            },
            error: function (xOptions,textStatus) {
            }
        });
    });
}

function onBackKeyDown() {
    jumpbyback(2,"");
}